<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>天天生鲜-订单管理</title>
<link rel="shortcut icon" href="images/copylogo.png">
<link rel="stylesheet" href="css/reset.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/order.css">
<!--  注意引入顺序 -->
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/check.js"></script>
<!-- layui -->
<link rel="stylesheet" href="layui/css/layui.css"  media="all">
<script src="layui/layui.js" charset="utf-8"></script>
</head>

<body>
	<!-- 头部  -->
	<div class="header_con">
		<div class="header">
			<div class="welcome fl">欢迎来到天天生鲜</div>
			<div class="fr">
				<div id="loginInfo" class="login_info fl">
					欢迎：<em>未登录</em> <span> | </span> <a href="javascript:loginOut()">退出登录</a>
				</div>
				<div id="loginBtn" class="login_btn fl">
					<a href="login.html">登录</a> <span> | </span> <a
						href="register.html">注册</a>
				</div>
				<div class="user_link fl">
					<span> | </span> <a href="user.html">用户中心</a> <span> | </span> <a
						href="cart.html">我的购物车</a> <span> | </span> <a href="order.html">我的订单</a>
				</div>
			</div>
		</div>
	</div>

	<!-- 搜素框 -->
	<div class="search_bar clearfix">
		<a href="index.html" class="logo fl"><img src="images/logo.png"></a>
		<div class="search_con fl">
			<input type="text" class="input_text fl" id="keyWord" placeholder="搜索商品"> 
			<input type="button" onclick="doSearch();" class="input_btn fr" value="搜索">
		</div>
	</div>

	<!-- 订单列表 -->

	<div class="common_list_con clearfix" id="order_list_title">
		<ul class="goods_list_th clearfix">
			<li class="col01">商品名称</li>
			<li class="col03">商品单位</li>
			<li class="col03">商品价格</li>
			<li class="col02">数量</li>
			<li class="col03">小计</li>
		</ul>
	</div>
	<div class="order_list_con" id="orderListView">
	</div>
	
	<div id="alipay"></div>
	<!-- 版权所有 -->
	<div class="footer">
		<div class="foot_link">
			<a href="#">关于我们</a> <span> | </span> <a href="#">联系我么</a> <span>
				| </span> <a href="#">招聘人才</a> <span> | </span> <a href="#">友情链接</a>
		</div>
		<p>CcpyRight &copy; 2019 衡阳市源辰信息科技有限公司 All Rights Reserverd</p>
		<p>电话：0734-8355998 湘ICP备16015987号</p>
	</div>
</body>

<script type="text/html" id="orderListModel">
{{#   layui.each(d.list,function(index,order){   }}

<div class="order_title">
{{#   var state = function(){   }}
{{#      if(order.status==1){ return '<a href="javascript:payNow('+order.ono+')">立即支付</a>'}   }}
{{#      if(order.status==2){ return '<a href="javascript:">等待发货</a>'}   }}
{{#      if(order.status==3){ return '<a id="state_'+order.ono+'" href="javascript:receipt('+order.ono+')">确认收货</a>'}   }}
{{#      if(order.status==4){ return '<a href="javascript:">已签收</a>'}   }}
{{#   }   }}
{{order.odate}} &emsp;&emsp; 订单号：{{order.ono}} &emsp;&emsp;共计：{{order.price}}元 &emsp;&emsp;配送地址： {{order.addrInfo.addr}} {{ state() }}
</div>
{{#   layui.each(order.orderItem,function(idex,item){   }}
<ul class="goods_list_td clearfix">
	<li class="col01">{{idex+1}}</li>

{{#   var pic = function(){   }}
{{#   return "<img src='"+item.goodsInfo.pics.split('|')[0]+"' />";       }}
{{#   };   }}
	<li class="col02">{{ pic() }}</li>
	<li class="col03">{{item.goodsInfo.gname}}</li>
	<li class="col04">{{item.goodsInfo.weight}}</li>
	<li class="col04">{{item.price}}元</li>
	<li class="col03">{{item.nums}}</li>
	<li class="col04"><em id="totalPrice_{{order.ono}}">{{item.price*item.nums}}</em>元</li>
</ul>
{{#   });   }}
{{#   });   }}
{{#   if(d.list.length==0){   }}
您暂无订单信息，快前往购买吧！&emsp;<a href="cart.html">跳转购物车</a>
{{#   }   }}
</script>

<script type="text/javascript">
var user = checkLogin();
if(user==null || user.mno<=0){
	location.href = "login.html";
}

var layer;		//引入layui弹框组件
layui.use('layer',function(){
	layer = layui.layer;
});
var laytpl;		//引入layui模板引擎
layui.use('laytpl',function(){
	laytpl = layui.laytpl;
});

$(function(){
	$.post("order/getByMno",{mno:user.mno},function(data){
		var data = {"list" :  data}
		var getTpl = orderListModel.innerHTML , view = document.getElementById('orderListView');
		laytpl(getTpl).render(data,function(html){
			view.innerHTML = html;
		});
	});
})

function payNow(ono){
	if(ono<=0){
		return;
	}
	var totalPrice = Number($.trim($("#totalPrice_"+ono).html()));
	console.log(totalPrice);
	$.post("alipay/pay",{ono:ono,price:totalPrice},function(data){
		$("#alipay").html(data)
		//document.write(data);
	});
}
function receipt(ono){
	layer.confirm('是否确认收货？',['确定','取消'],function(index){
		$.post("order/mdfyStateByOno",{ono:ono,op:'receipt'},function(data){
			layer.close(index);
			data = parseInt($.trim(data));
			data>0 ? $("#state_"+ono).html('已签收') : layer.msg("操作请稍后重试",{icon:5});
		},"json");
	})
}
</script>
</html>
